﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace game
{
    public class PlasmaGun : Weapon
    {
        public PlasmaGun(Scene scene, Ship shooter)
            : base(scene, shooter)
        {
            shotIntervalMs = 150;
            loadSpeed = 0.0002f;
            shotLoadCost = 0.1f;
        }

        bool left = true;

        public override bool Shoot(int layerIndex, Vector3 position, Vector3 rotation, Vector3 velocity)
        {
            if (!CanShoot())
            {
                return false;
            }

            Vector3 offset = -200.0f * Vector3.Transform(
                    Vector3.Forward, Matrix.CreateRotationY(rotation.Y));

            position += offset;

            Vector3 movement = Vector3.Transform(new Vector3(1000, 0, 0), Matrix.CreateRotationZ(rotation.Z));
            movement = Vector3.Transform(movement, Matrix.CreateRotationY(rotation.Y));

            Projectile p;
            if (left)
            {
                p = new PlasmaCell(scene, shooter, layerIndex, position - movement, rotation);
                scene.BilboardMgr.PlasmaShot(position - movement, velocity);
            }
            else
            {
                p = new PlasmaCell(scene, shooter, layerIndex, position + movement, rotation);
                scene.BilboardMgr.PlasmaShot(position + movement, velocity);
            }
            p.InitialVelocity = velocity;

            scene.AddObject(
                p, layerIndex);

            left = !left;

            scene.SoundMgr.Plasma(position);

            ShootUpdate();

            return true;
        }
    }
}
